clear
anni = (1900:2007)';
yy = kron(anni,ones(4,1));
qq = kron(ones(size(anni,1),1),([3 6 9 12])'); 
DATE = [yy qq]; nn = datenum(DATE(:,1),DATE(:,2), 15); 
% results_var_gdp_m2_and_ar_ 
% results_var_infl_gdp_and_ar_ 
for j = 99:519
    j
    eval(['load ', 'results_var_infl_gdp_and_ar_',num2str(j)]);
    for h=1:12
        fore_var{h}(j,1) = median(fore_var_tv_m_cum_gibb{h}(1,:));
        tt{h}(j,1)=true_cum{h}(end,1);
        fore_ar{h}(j,1) = median(fore_ar_tv_m_cum_gibb{h}(1:end));
 
        msfe_ar{h}(:,j) = ((fore_ar_tv_m_cum_gibb{h})-kron(true_cum{h}(end,1),ones(401,1))).^2;
        msfe_var{h}(:,j) = ((fore_var_tv_m_cum_gibb{h}(1,:))'-kron(true_cum{h}(end,1),ones(401,1))).^2;
        %
        %      mmsfe_ar{h}(j,1) = (median(fore_ar_tv_m_cum_gibb{h},1)-true_cum{h}(end,1))^2;
        %      mmsfe_var{h}(j,1) = (median(fore_var_tv_m_cum_gibb{h}(1,:)',1)-true_cum{h}(end,1))^2;
    end
end
 
win=31;
for h = 1:12
    for i= 1:size(msfe_ar{h}(:,99:end),1)
        m_ar{h}(i,:) =   filter(ones(1,win),1,msfe_ar{h}(i,99:end));
        m_var{h}(i,:) =  filter(ones(1,win),1,msfe_var{h}(i,99:end));
    end
end
 
for h = 1:12
    MSFE_ar{h} = m_ar{h}(:,win:end);
    MSFE_var{h} =  m_var{h}(:,win:end);
end
 
 
for h=1:12
    err_var(:,h) = ([tt{h}(99:end,1)-fore_var{h}(99:end,1) ].^2);
    err_ar(:,h) = ([ tt{h}(99:end,1)-fore_ar{h}(99:end,1)].^2);
end

 
  figure(10);
 count = 0; 
 for h=[1 4 8 12]
    count = count+1;
 subplot(2,2,count);

plot(nn(floor(win/2)+h:floor(win/2)+size(MSFE_var{h}+h,2)+h-1),[ones(size(MSFE_var{h}+h,2),1) prctile(MSFE_var{h}./MSFE_ar{h},[16 50 84],1)']); datetick('x','yyyy','keepticks'); 
hold on
plot([datenum(1914,9,15) datenum(1914,9,15)], [0 5]); axis([696410 732021 0 5] )
plot([datenum(1931,6,15) datenum(1931,6,15)], [0 5]); axis([696410 732021 0 5] )
plot([datenum(1941,9,15) datenum(1941,9,15)], [0 5]); axis([696410 732021 0 5] )
plot([datenum(1951,3,15) datenum(1951,3,15)], [0 5]); axis([696410 732021 0 5] )
plot([datenum(1971,9,15) datenum(1971,9,15)], [0 5]); axis([696410 732021 0 5] )
plot([datenum(1983,12,15) datenum(1983,12,15)], [0 5]); axis([696410 732021 0 5] )
hold off
title(h)
% set(gcf,'DefaultAxesColorOrder',[0 0 0;1 0 0;1 0 0;0 0 1]); 
end
 
 